home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d18
/
microt.arc
/
TIMING.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1990-10-10
|
5KB
|
143 lines
(* Several programs have been evaluated for accurate time delay procedures
with accuracy greater than the Turbo Pascal 1 millisecond resolution. A few
have used the computer clock timing chip, resetting the chip then following
procedures:
procedure Initialize;
{-Reprogram the timer chip to allow 1 microsecond resolution}
begin {InitializeTimer}
{select timer mode 2, read/write channel 0}
Port[$43] := $34; {00110100b}
inline($EB/$00); {jmp short $+2 ;delay}
Port[$40] := $00; {LSB = 0}
inline($EB/$00); {jmp short $+2 ;delay}
Port[$40] := $00; {MSB = 0}
end; {InitializeTimer}
procedure Restore;
{-Restore the timer chip to its normal state}
begin {RestoreTimer}
{select timer mode 3, read/write channel 0}
Port[$43] := $36; {00110110b}
inline($EB/$00); {jmp short $+2 ;delay}
Port[$40] := $00; {LSB = 0}
inline($EB/$00); {jmp short $+2 ;delay}
Port[$40] := $00; {MSB = 0}
end; {RestoreTimer}
The use of the above has been found to stop the time function if TSR or
application programs require reporting the then current time. As a result
the computer time has to be reset using the DOS "time" commnad.
An alternative has been found which uses the timer chip that drives the
speaker within the computer. The same timing accuracy is the basis for
measurement, i.e., the counts per second are 1193181.667. The actual
resolution therefore is 0.838 microsecond per count. No resetting of the
computer time clock is required however. The Port that is read if either
Port[$61] or Port[$62], depending on your computer type (AT or XT).
The following is an example of how to use the new timing procedure *)
Program TimeTest;
{$M 1024,10240,10240}
Uses Crt;
Var
machineID : Byte absolute $FFFF : $000E;
(* Information return from Byte $FFFF : $000E for various Machines:
$FF PC
$FE XT
$FB Later Model XT
$FD PC Junior
$FC XT-286, AT, PS/2 Model 50 & 60
$FA PS/2 Model 30
$F9 : PC Convertible
$F8 : PS/2 Model 70 & 80 *)
read_port : byte; (* port to read, depending on Machine code *)
clock_count : longint; (* Longint used to allow over a second timing
with multiples of 1193182 counts per second
and up to 2147483647/1193182 = 1799.8 seconds
(30 minutes) *)
Procedure Test_Delay_Timing;
var
Count : longint;
Accum_Count : word;
Ch : Char;
I, J : Shortint;
CStr : string[5];
err : Integer;
Begin
if MachineID = $FB then read_port := $62 else read_port := $61;
ClrScr;
writeLn('Enter delay time to test in decimal Microseconds');
WriteLn('100000 Microseconds will equal a Second, entry over');
Writeln('up to 65536 Microseconds allowed, default to 55536 Microseconds maximum');
repeat
Readln(CStr);
val(CStr,count,err);
writeln('Count ',count);
writeln('lo(count) ',lo(count));
writeln('hi(count) ',hi(count));
if MachineID = $FB then read_port := $62 else read_port := $61;
writeln('MachineId ',machineID);
writeln('Read_Port ',read_port);
Port[$43] := $B2; {Set timer chip to one shot mode*}
(* Program timer chip, lower byte first then higher byte *)
Port[$42] := lo(count); {lower byte}
Port[$42] := hi(count); {higher byte}
Accum_Count := 0;
Port[$61] := Port[$61] AND $FC;{trigger timer}
port[$61] := Port[$61] OR $01;{start count at 1}
(* Bit 5 of I/O port remains low until clock cycles = count *)
for I := 1 to 10 do
begin
repeat
until Port[$61] AND $20 <> 0; {read bit 5 until low,
AND $20 allows read bit 5 only }
Port[$61] := Port[$61] AND $FC;{trigger timer}
port[$61] := Port[$61] OR $01;{start count at 1}
Accum_Count := Accum_Count + Port[Read_Port];
end;
writeln(Accum_Count,' Number of counts');
writeLn(Accum_Count/1193182*1000000:0:1,' Microseconds delay');
until count = 0;
end;
Procedure Test_Write_to_Screen_time;
var
X, Y, I : Shortint;
Count : Longint;
Ch : Char;
Begin
if MachineID = $FB then read_port := $62 else read_port := $61;
Port[$43] := $B2; {Set timer chip to one shot mode*}
Port[$61] := Port[$61] AND $FC;{trigger timer}
port[$61] := Port[$61] OR $01;{start count at 1}
For X := 1 to 80 do {Columns}
For Y := 1 to 25 do {Rows}
Begin
Gotoxy(X,Y);
Write('A');
End;
Count := Port[read_port]; {read counts}
WriteLn(Count,' Clock counts occurred');
writeLn(Count/1193182*1000000:0:1,' Microseconds to write 80 characters');
Ch := ReadKey;
end;
BEGIN
clrscr;
Test_Write_to_Screen_time;
Test_Delay_Timing;
End.